package pl.un4giv3n.mightvsmagic.action.clan;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

public class StopPendingClanAction extends ClanAction{

	private static final long serialVersionUID = 1L;

	@Override
	public String execute() {
		EntityManager entityManager = getEntityManager();
		user = getSessionUser(entityManager);
		if (user == null) {
			addActionError("Zaloguj się");
			entityManager.close();
			return LOGIN;
		}
		EntityTransaction transaction = entityManager.getTransaction();
		transaction.begin();
		user.setClan(null);
		user.setClanAcceptancePending(false);
		entityManager.merge(user);
		entityManager.flush();
		transaction.commit();
		entityManager.close();
		return SUCCESS;
	}
}
